package com.reremouse.rerebbs.model;

import com.reremouse.rerebbs.dao.IBbsThreadDAO;
import com.reremouse.util.SpringHelper;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "rerebbs_thread")
public class BbsThread
        implements Serializable, Comparable {
    @Id
    @Column(name = "id", unique = true, nullable = false)
    private Long id = Long.valueOf(System.nanoTime());
    @Column(name = "title", length = 200)
    private String title;
    @Column(name = "genTime", nullable = false, length = 0)
    @Temporal(TemporalType.TIMESTAMP)
    private Date genTime;
    @ManyToOne(targetEntity = BbsUser.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "genBy")
    private BbsUser genBy;
    @ManyToOne(targetEntity = BbsZone.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "zone")
    private BbsZone zone;
    @Column(name = "readCount")
    private Integer readCount;
    @Column(name = "top")
    private boolean top = false;
    @OneToOne(fetch = FetchType.LAZY, cascade = {javax.persistence.CascadeType.PERSIST})
    @JoinColumn(name = "last_talk_id")
    private BbsTalk latestTalk;
    @OneToMany(fetch = FetchType.LAZY, cascade = {javax.persistence.CascadeType.REMOVE}, mappedBy = "thread")
    private List<BbsTalk> talks;
    @Transient
    private long replyCount;

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getGenTime() {
        return this.genTime;
    }

    public void setGenTime(Date genTime) {
        this.genTime = genTime;
    }

    public BbsUser getGenBy() {
        return this.genBy;
    }

    public void setGenBy(BbsUser genBy) {
        this.genBy = genBy;
    }

    public BbsTalk getLatestTalk() {
        return this.latestTalk;
    }

    public void setLatestTalk(BbsTalk latestTalk) {
        this.latestTalk = latestTalk;
    }

    public BbsZone getZone() {
        return this.zone;
    }

    public void setZone(BbsZone zone) {
        this.zone = zone;
    }

    public Integer getReadCount() {
        return this.readCount;
    }

    public void setReadCount(Integer readCount) {
        this.readCount = readCount;
    }

    public long getReplyCount() {
        IBbsThreadDAO threadDAO = (IBbsThreadDAO) SpringHelper.getSpringBean("BbsThreadDAO");
        this.replyCount = (threadDAO.getTalksNumByThread(this.id.longValue()) - 1L);
        return this.replyCount;
    }

    public void setReplyCount(long replyCount) {
        this.replyCount = replyCount;
    }

    public List<BbsTalk> getTalks() {
        return this.talks;
    }

    public void setTalks(List<BbsTalk> talks) {
        this.talks = talks;
    }

    public boolean isTop() {
        return this.top;
    }

    public void setTop(boolean top) {
        this.top = top;
    }

    public int compareTo(Object o) {
        BbsThread os = (BbsThread) o;
        return this.latestTalk.getGenTime().compareTo(os.latestTalk.getGenTime());
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.model.BbsThread

 * JD-Core Version:    0.7.0.1

 */